# 
# Created by francklinson on 2021/7/29 AT 23:21.
#
# 给定两个字符串 s1 和 s2，请编写一个程序，确定其中一个字符串的字符重新排列后，能否变成另一个字符串。
from typing import List
from collections import Counter


class Solution:
    def CheckPermutation(self, s1: str, s2: str) -> bool:
        return sorted(s1) == sorted(s2)


class Solution2:
    def CheckPermutation(self, s1: str, s2: str) -> bool:
        if len(s1) != len(s2):
            return False
        ct1 = Counter(s1)
        ct2 = Counter(s2)
        for char, nums in ct1.items():
            if char not in ct2.keys() or ct2[char] != nums:
                return False
        return True


if __name__ == '__main__':
    sol = Solution2()
    print(sol.CheckPermutation(s1="abc", s2="bca"))
    print(sol.CheckPermutation(s1="abc", s2="bad"))
